package org.xg.study.pd.util;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName RedisUtils
 * @date 2021/9/15 16:20
 **/
public class RedisUtils {
    private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);

    private AtomicInteger stock = new AtomicInteger(0);

    public RedisUtils(){
        scheduledExecutorService.scheduleAtFixedRate(() -> {
            //模拟库存消耗
            stock.addAndGet(1);
        },0,100, TimeUnit.MILLISECONDS);
    }

    public int getStockUsed(){
        return stock.get();
    }
}
